package com.dlshouwen.wzgl.baseinfo.dao;

import java.util.List;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.dlshouwen.core.base.dao.BaseDao;
import com.dlshouwen.wzgl.baseinfo.model.BaseInfo;

@Repository
public class BaseInfoDao extends BaseDao {
	//注入数据源
    @Resource(name = "defaultDataSource")
    public void setDataSource(DataSource dataSource) {
        super.setDataSource(dataSource);
    }
    
    public BaseInfo select() {
    	String sql = "select * from wzgl_baseinfo";
    	RowMapper<BaseInfo> rowMaper = ParameterizedBeanPropertyRowMapper.newInstance(BaseInfo.class);
    	List<BaseInfo> list = this.query(sql, rowMaper);
    	BaseInfo baseInfo = null;
    	if(null != list && list.size() > 0) {
    		baseInfo = list.get(0);
    	}
    	return baseInfo;
    }
    
    public int update(BaseInfo obj) throws Exception {
    	StringBuilder sql = new StringBuilder();
        StringBuilder str = new StringBuilder();
        updateSql(str, BaseInfo.class, obj);
        sql.append("update wzgl_baseinfo set ").append(str);
        sql.append(" where id=${id }");
        
        return this.updateObject(sql.toString(), obj);
    }
}
